<?php

namespace App\Console\Commands;

use App\Library\Logic\LogisticsLogic;
use App\Models\ShopExpressDeliveryModel;
use Illuminate\Console\Command;

class SyncExpressCommand extends Command
{
    /**
     * 同步物流信息
     *
     * @var string
     */
    protected $signature = 'command:syncExpress';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $model = ShopExpressDeliveryModel::query()->get();
        if (!is_null($model)) {
            foreach ($model as $item) {
                LogisticsLogic::insertForModel([
                    'objectType' => in_array($item->ed_type, [1, 2]) ? 1 : 0,//'订单类型;0:auction;1:product;',
                    'objectId' => $item->ed_source_id,
                    'type' => $item->ed_type === 1 ? 0 : 1,//type;0订单1退货2换货3补货
                    'expressNo' => $item->ed_sn,
                    'statusSign' => !is_null($item->ed_content),
                    'info' => !is_null($item->ed_content) ? json_decode($item->ed_content, true) : '',
                ]);
            }
        }
    }
}
